<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>dom添加事件</title>

    <script>



        function load() {
            var btn = document.getElementById("button1")
            console.log(btn)

            btn.onclick = function() {
                console.log("11111111111")
            }
        }

    </script>

</head>
<body onload="load()">      <!-- body标签的onload属性设置文档加载结束之后，触发指定函数初始化 -->

<button id="button1">我是按钮1</button>
<button id="button2">我是按钮2</button>



<script>
    function test2() {
        alert("按钮2被点击")
    }
    var btn = document.getElementById("button2")
    btn.onclick = test2()


</script>


</body>
</html>